import type { PageType } from "@/api/type";
import request from "@/utils/request";
import type {
    SocPostItemVO,
    SocPostReplyDTO,
    SocPost,
    SocPostCreateDTO,
    SocPostInfoVO,
    SocPostLikes,
    SocPostCategory,
    PostUserInfoVO,
    SocPostCategoryTrreVO
} from "./type";

enum API {
    POSTS_PAGE_URL = "/social/posts/page",
    POSTS_URL = "/social/posts",
    POST_INFO="/social/posts/info",
    POSTS_REPLY_URL="/social/posts/replies",
    REPLY_PAGE="/social/posts/replies/page",
    POST_LIKE_URL="/social/posts/likes",
    POST_CATEGORY_LIST="/social/post/category/list",
    POST_CATEGORY_TREE_LIST="/social/post/category/tree-list",
    POST_USER="/social/posts/user"
}

export function reqGetPostPage(params: object) {
    return request<PageType<SocPostItemVO>>({
        url: API.POSTS_PAGE_URL,
        method: 'get',
        params
    })
}
/**
 * 创建帖子的请求
 * @param data
 * @returns
 */
export function reqCreatePost(data: SocPostCreateDTO) {
    return request<PageType<SocPost>>({
        url: API.POSTS_URL,
        method: 'post',
        data
    })
}

export function reqGetPostById(postId: string) {
    return request<SocPostItemVO>({
        url: API.POSTS_URL + "/" + postId,
        method: 'get',
    })
}
export function reqGetPostInfoVO(socPostDetailDTO:object){
    return request<SocPostInfoVO>({
        url: API.POST_INFO ,
        method: 'get',
        params:socPostDetailDTO
    })
}
export function reqCreatePostReply(data: SocPostReplyDTO) {
    return request({
        url: API.POSTS_REPLY_URL,
        method: 'post',
        data
    })
}
export function reqLikePost(data:SocPostLikes){
    return request({
        url: API.POST_LIKE_URL,
        method: 'post',
        data
    })
}
export function reqGetPostCategoryList(){
    return request<SocPostCategory[]>({
        url: API.POST_CATEGORY_LIST,
        method: 'get',
    })
}
export function reqGetPostCategoryTreeList(){
    return request<SocPostCategoryTrreVO[]>({
        url: API.POST_CATEGORY_TREE_LIST,
        method: 'get',
    })
}
export function reqGetPostUserById(userId: string){
    return request<PostUserInfoVO>({
        url: API.POST_USER + "/" + userId,
        method: 'get',
    })
}
export function reqGetPostReplyPage(params: object) {
    return request<PageType<SocPostReplyDTO>>({
        url: API.REPLY_PAGE,
        method: 'get',
        params
    })
}
